package com.iot.util;

import org.springframework.format.datetime.joda.LocalTimeParser;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @author wlr
 * @date 2022/1/6 15:38
 */
public class DateFormat {
    public LocalDateTime strToLocalDateTime(String str){
        String date = DateFormat.millisecondToDate(str);
        return DateFormat.stringToLocalDateTime(date);
    }
    public static String millisecondToDate(String str) {
        Date date = new Date(Long.valueOf(str));
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        String time = format.format(date);
        return time;
    }
    public static LocalDateTime stringToLocalDateTime(String str){
        DateTimeFormatter df=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return LocalDateTime.parse(str, df);
    }
}
